package com.wu.common.page;


import com.wu.common.query.PageQuery;

public class PageQueryWrapper<T> extends PageQuery<T> {
    private static final long serialVersionUID = 1L;
    private int itemCount;
    private int startRow;
    private int endRow;

    public PageQueryWrapper(int pageNo, int pageSize, int itemCount, T t) {
        super(pageNo, pageSize);
        this.itemCount = itemCount;
        this.setQuery2(t);
        this.startRow = this.getStartIndex() < 1 ? 0 : this.getStartIndex() - 1;
        this.endRow = this.getEndIndex();
    }

    public int getItemCount() {
        return this.itemCount;
    }

    public int getStartRow() {
        return this.startRow;
    }

    public int getEndRow() {
        return this.endRow;
    }

    private int getStartIndex() {
        return (this.getPageNo() - 1) * this.getPageSize() + 1;
    }

    private int getEndIndex() {
        int end = this.getPageNo() * this.getPageSize();
        if (end > this.itemCount) {
            end = this.itemCount;
        }

        return end;
    }
}

